package com.honyelchak.shortlink.admin.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

@Configuration
public class UserConfiguration {

    /**
     * 用户上下文传递过滤器
     * @param stringRedisTemplate
     * @return
     */
    @Bean
    public FilterRegistrationBean<UserTransmitFilter> globalUserTransmitFilter(StringRedisTemplate stringRedisTemplate){
        FilterRegistrationBean<UserTransmitFilter> filterFilterRegistrationBean = new FilterRegistrationBean<>();
        filterFilterRegistrationBean.setFilter(new UserTransmitFilter(stringRedisTemplate));
        filterFilterRegistrationBean.addUrlPatterns("/*");

        filterFilterRegistrationBean.setOrder(0);
        return filterFilterRegistrationBean;
    }
}
